<?php 

namespace App\Http\Controllers\Admin;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Admin\ThrottlesLogins;
use Illuminate\Foundation\Admin\AuthenticatesAndRegistersUsers;
use Illuminate\Http\Request;
use App\Http\Requests;
use DB;

class NodeController extends Controller
{
	public $model=false;

	public function __construct(){
	     $this->model = new \App\Node();
	}

	//权限列表
	public function node_list(){
		$node_title = isset($_GET['node_title'])?$_GET['node_title']:'';

		$info= $this->model->lists($node_title);

		return view('Admin/node/node_list',['info'=>$info,'node_title'=>$node_title]);
	}

	//权限添加
	public function node_add(){
		if($_POST){
			$res=$this->model->add($_POST);
			if($res){
				echo '<script>alert("添加权限成功");window.location.href="node_list";</script>';
			}else{
				echo '<script>alert("添加权限失败");window.location.href="node_add";</script>';
			}
		}else{	
			return view('Admin/node/node_add');
		}
	}

	//获取当前等级的父级
	public function getlist($level){
		$list =$this->model->getList($level);
		echo json_encode($list);
	}

	//修改权限信息
	public function node_edit($node_id){
			if(empty($_POST)){
				$arr=$this->model->fineOne($node_id);
				$listOne=$arr['oneList'];
				$fulist=$arr['fulist'];
				return view('Admin/node/node_edit',['listOne'=>$listOne,'fulist'=>$fulist]);
			}else{
				$res=$this->model->up($_POST);
				if($res){
					return redirect('/admin/node_list');
				}else{
					echo '<script>alert("修改权限失败");window.location.href="node_add";</script>';
				}
			}
	}

	//删除权限  修改状态
	public function node_del($node_id){
		$res=$this->model->del($node_id);
		if($res){
			return redirect('/admin/node_list');
		}else{
			echo '<script>alert("删除权限失败");window.location.href="node_add";</script>';
		}
	}

	//还原权限  修改状态
	public function node_back($node_id){
		$res=$this->model->back($node_id);
		if($res){
			return redirect('/admin/node_list');
		}else{
			echo '<script>alert("删除权限失败");window.location.href="node_add";</script>';
		}
	}

}



 ?>

